import { getBanner } from './service'

const initState = {
  text: '首页',
  banner: [],
}

export default {
  namespace: 'home',
  state: initState,
  effects: {
    *fetch (_, { put }) {
      yield put({
        type: 'getBanner',
      })
    },
    *getBanner (_, { put, call }) {
      const { data } = yield call(getBanner, {
        type: 'index',
      });
      yield put({ type: 'save', payload: { banner: data } });
    },
  },
  reducers: {
    save (state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
}
